#!/bin/bash

# first argument picks test set: f/b/l/_ (for trace_test)
# second picks predictors: i/t/_ (for conditional)
# f/b/l i
# gshare+ gshare_base gshare_unlimited gshare_nocol

#decide test set:
case $1 in
	f) TESTS=( ../trace_test.bz2 ../traces/WS05* ../traces/MM01* ) ;;
	b) TESTS=( ../traces/MM01* ) ;;
	l) TESTS=( ../traces/INT04* ../traces/CLIENT05* ../traces/WS04* ../traces/SERVER03* ../traces/MM04* ) ;;
	*) TESTS=( ../trace_test.bz2 ) ;;
esac

case $2 in
#	l) PREDICTORS=( gshare gshare+ gshare++ ) ;;
#        t) PREDICTORS=(  gshare_path ) ;;
	#gshare_large gshare_larger 
	*) PREDICTORS=( gshare_large gshare_base gshare_base_cheat gshare_nocol gshare_unlimited gshare_path local_limited local_nocol local_unlimited ISL_TAGE-cond );; 
#	*) PREDICTORS=( gshare local perceptron ogehl ISL_TAGE-cond ) ;;
esac

echo "Tests: ${TESTS[*]}";
echo "Predictors: ${PREDICTORS[*]}";

mkdir results
cd results

# list of predictors to use
for e in ${PREDICTORS[*]}
do
	cd ../$e
	make links 2>/dev/null #hides error output
        make clean
	make
	cd -
	echo "running tests on predictor: $e"
	# list of tests to use
	for t in ${TESTS[*]}
	do
		# note that "../traces/" has lenght 10
		# and the end has lenght 4 ".bz2"
		let "ln=(${#t}-10-4)" #correct length 10 for prefix, 4 for extension and dot
		ln=${t:10:$ln} # simplified test name
		#echo "output.$e.$ln"

		echo "predictor: $e ; test: $t"
		../$e/cbp3 -t $t > output.$e.$ln
		# counts
		mv conditional_count.csv conditional_count.$e.$ln.csv
		#mv indirect_count.csv indirect_count.$e.$ln.csv
		# classes THIS WILL OVERWRITTE SINCE ALL TESTS should yield the same... (not checked)
		# these are final results FOR THE TEST
		mv conditional_class.csv results.conditional_class.$ln.csv
		#mv indirect_class.csv results.indirect_class.$ln.csv
		# branch trace
		mv conditional_trace.csv conditional_trace.$e.$ln.csv
		#mv indirect_trace.csv indirect_trace.$e.$ln.csv
		echo "done."
	done
done

